import mongoose, {
  Document,
  Schema,
} from 'mongoose';

import { IUser } from '@shared/types/user';

export interface IUserDocument extends Omit<IUser, '_id'>, Document {}

const userSchema: Schema = new Schema({
  username: { type: String, required: true },
  password: { type: String, required: true },
  phone: { type: String, required: true, unique: true },
  role: { type: String, enum: ['admin', 'user'], default: 'user' },
  create_time: { type: Date, default: Date.now },
  status: { type: String, enum: ['active', 'disabled'], default: 'active' },
  is_deleted: { type: Boolean, default: false },
  deleted_at: { type: Date }
});

export const User = mongoose.model<IUserDocument>("User", userSchema);
